import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import axios from 'axios'
import './assets/css/_reset.scss'
import './assets/css/element-ava.scss'

import moment from 'moment'

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://157.122.54.189:9095'

Vue.prototype.$moment = moment

axios.interceptors.request.use(config => {
  return config
}, error => {
  return Promise.reject(error)
})

axios.interceptors.response.use(response => {
  return response
}, error => {
  if (error && error.response) {
    switch (error.response.status) {
      case 400:
        error.message = '错误请求'
        break
      case 401:
        error.message = '未授权'
        break
      case 403:
        error.message = '拒绝访问'
        break
      case 404:
        error.message = '请求错误，未找到资源'
        break
      case 405:
        error.message = '请求方法未允许'
        break
      case 408:
        error.message = '请求超时'
        break
    }
    console.log(error.message)
    // 未登陆跳转到登陆面
    if (error.response.status === 401 || error.response.status === 403) {
      router.push({ path: '/user' })
    }
  }
})
